package com.lqm.service.home.impl;

import com.lqm.dao.CommentsDao;
import com.lqm.entity.home.Comments;
import com.lqm.entity.home.Project;
import com.lqm.service.home.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class CommentsServiceImpl implements CommentsService {

    @Autowired
    CommentsDao commentsDao;
    @Override
    public List<Comments> findAllByProject(Project project, int limit, int page) {
        Sort sort = new Sort(Sort.Direction.DESC, "commentsId");
        Pageable pageable = PageRequest.of(page - 1, limit, sort);
        return commentsDao.findAllByProject(project,pageable);
    }

    @Override
    public Comments addComments(Comments comments) {
        return commentsDao.save(comments);
    }


}
